import {
  getCurDate,
  setSessionStorage,
  getSessionStorage,
  removeSessionStorage,
  setLocalStorage,
  getLocalStorage,
  removeLocalStorage
} from './utils/common.js'
import echarts from 'echarts'
import qs from 'qs'


export default {
  install(Vue) {
    Vue.prototype.$target = "http://127.0.0.1:3000/"  // 线上图片地址
    
    // 封装提示成功的弹出框
    Vue.prototype.notifySucceed = function (msg) {
      this.$notify({
        title: "成功",
        message: msg,
        type: "success",
        offset: 100
      });
    }
    // 封装提示失败的弹出框
    Vue.prototype.notifyError = function (msg) {
      this.$notify.error({
        title: "错误",
        message: msg,
        offset: 100
      })
    }

    Vue.prototype.$getCurDate = getCurDate;
    Vue.prototype.$setSessionStorage = setSessionStorage;
    Vue.prototype.$getSessionStorage = getSessionStorage;
    Vue.prototype.$removeSessionStorage = removeSessionStorage;
    Vue.prototype.$setLocalStorage = setLocalStorage;
    Vue.prototype.$getLocalStorage = getLocalStorage;
    Vue.prototype.$removeLocalStorage = removeLocalStorage;

    Vue.prototype.$echarts = echarts;
    Vue.prototype.$qs = qs;

    // 相对时间过滤器,把时间戳转换成时间
    // 格式: 2020-02-25 21:43:23
    Vue.filter('dateFormat', (dataStr) => {
      var time = new Date(dataStr);

      function timeAdd0(str) {
          if (str < 10) {
              str = '0' + str;
          }
          return str;
      }
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) + ' ' + timeAdd0(h) + ':' + timeAdd0(mm) + ':' + timeAdd0(s);
    });

  }
}